﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ParkingLot.Utility
{

    /// <summary>
    /// 配置文件管理类(管理本类DLL的配置文件)
    /// </summary>
    public static class ConfigManager
    {
        readonly static bool m_Error;

        static Configuration m_AppConfig;

        static ConfigManager()
        {
            string assemblyName = typeof(ConfigManager).Assembly.GetName().Name;
            string dllPath = string.Format(
                "{0}\\{1}.dll", AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory, assemblyName);

            try
            {
                m_AppConfig = ConfigurationManager.OpenExeConfiguration(dllPath);
                #region 加入Ini文件

                #endregion
              
                //m_AppConfig.AppSettings.Settings.Add(new KeyValueConfigurationElement(,))
            }
            catch (ConfigurationErrorsException)

            {
                m_Error = true;
            }
        }

        public static KeyValueConfigurationCollection AppSettings
        {
            get
            {
                if (m_Error) return null;
                return m_AppConfig.AppSettings.Settings;
            }
        }

        public static ConnectionStringSettingsCollection ConnectionStrings
        {
            get
            {
                if (m_Error) return null;
                return m_AppConfig.ConnectionStrings.ConnectionStrings;
            }
        }
    }
}
